/**************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
* File Name          : IRScan.h
* Author             : Billy Long Fortiortech  Market Dept
* Version            : V1.0
* Date               : 01/07/2015
* Description        : This file contains all the common data types used for Motor Control.
***************************************************************************************************
* All Rights Reserved
**************************************************************************************************/

/* Define to prevent recursive inclusion --------------------------------------------------------*/
#ifndef __IRSCAN_H_
#define __IRSCAN_H_

#include "FU68xx_4_MCU.h"

#define     ShortPressMode                                  (0)
#define     LongPressMode                                       (1)
#define     UserCodeStudyMode                               (LongPressMode) //遥控学习模式：ShortPressMode:短按某个键执行学习；
//LongPressMode：长按某个键学习
//#define       StudyCode                                     (DUIMA)                                                   //对应执行学习功能的按键

#define     UserCodeLength                      (16)                            //定义遥控地址码长度
#define     DataCodeLength                      (16)                             //定义遥控数据码长度
#define     CheckCodeLengh                      (0)
#define     AllCodeLength                       (UserCodeLength+DataCodeLength+CheckCodeLengh)                                                          //定义遥控数据码长度

/*IR Scan Parameter*/
//#define     IRBitValue1TimeMax                (0.80)            // 数据为1时高电平长度最大值，单位ms
//#define     IRBitValue1TimeMin                (0.70)           // 数据为1时高电平长度最小值，单位ms
//#define     IRBitValue0TimeMax                (0.30)           // 数据为0时高电平长度最大值，单位ms
//#define     IRBitValue0TimeMin                (0.20)           // 数据为0时高电平长度最小值，单位ms
//#define     IRLeadCodeTimeMax                 (8.5)                  // 引导码周期长度最大值，单位ms
//#define     IRLeadCodeTimeMin                 (7.5)
#define 	IRBitValue1TimeMax                (1.85)            // 数据为1时高电平长度最大值，单位ms
#define 	IRBitValue1TimeMin                (1.45)           // 数据为1时高电平长度最小值，单位ms
#define 	IRBitValue0TimeMax                (0.80)           // 数据为0时高电平长度最大值，单位ms
#define 	IRBitValue0TimeMin                (0.45)           // 数据为0时高电平长度最小值，单位ms
#define 	IRLeadCodeTimeMax				  (5.5)					 // 引导码周期长度最大值，单位ms
#define 	IRLeadCodeTimeMin				  (3.5)						 // 引导码周期长度最小值，单位ms		

/*IR Scan (1500.0) */
#define TempBitValue1Max                      (uint16)(2775)//(uint16)(IRBitValue1TimeMax*TIM3_Fre)
#define TempBitValue1Min                      (uint16)(2175)//(uint16)(IRBitValue1TimeMin*TIM3_Fre)
#define TempBitValue0Max                      (uint16)(1200)//(uint16)(IRBitValue0TimeMax*TIM3_Fre)
#define TempBitValue0Min                      (uint16)(675)//(uint16)(IRBitValue0TimeMin*TIM3_Fre)
#define TempLeadCodeMax                       (uint16)(8250)//(uint16)(IRLeadCodeTimeMax*TIM3_Fre)
#define TempLeadCodeMin                       (uint16)(5250)//(uint16)(IRLeadCodeTimeMin*TIM3_Fre)


/*遥控码定义*/
//#define IRALLOFF                          (0X00EF)   //总关
//#define IRFRCW                            (0X0004)
//#define IRFRCCW                           (0X0011)

#define IRSpeed1                            (0X007F)
#define IRSpeed2                            (0X00BF)
#define IRSpeed3                            (0X003F)//DATACODE = 0x0000
#define IRSpeed4                            (0X00DF)
#define IRSpeed5                            (0X005F)//DATACODE = 0x0000
#define IRSpeed6                            (0X0057)//DATACODE = 0x0010
#define IRSpeed7                            (0X0037)//DATACODE = 0x0010



#define IRAUTOPOWER1H                                 (0X006F)
#define IRAUTOPOWER2H                                 (0X00F7)
#define IRAUTOPOWER4H                             		(0X00D7)
#define IRAUTOPOWER6H                                 (0X009F)
#define IRAUTOPOWER8H                                 (0X00B7)
#define IRNatureWind                                  (0x001F)//(0x0015)

#define IRLED                                       (0X001F)
#define IRONOFF                                     (0X00EF)//

/* Exported types -------------------------------------------------------------------------------*/
typedef struct
{
//    uint8   BYTE0;
//    uint8   BYTE1;
//    uint8   BYTE2;
//    uint8   BYTE3;
//    uint8   PID;
//    uint8   B;
    
    uint32  BitValue;
    uint8   BitCnt;
    uint16  Bit0Cnt;
//    uint32  ByteValue;
    
    uint16  UserCode;
    uint16  DataCode;
    uint16  CurrentUserCode;
    uint16  CurrentDataCode;
	
	//uint16	CurrentUserCode1;
    //uint16	CurrentUserCode2;
    
//    uint8 DataCodeNum;
//    uint16 TempDataCode[4];
    uint8   IRReceiveFlag;
//    uint8   OldDataCodeMixTimes0;
//    uint8   OldDataCodeMixTimes1;
    uint8 OverFlowStatus;

} IRScan_TypeDef;

typedef struct
{
    //uint8   NatureFlage;
    uint8   LEDONOFFStatus;
    uint8   FlagONOFF;
    uint8   ONOFFStatus;
    //uint8   FlagFR;
    uint8   FlagSpeed;
//    uint8     FlagLED;
//	  uint8     FlagLED_count;
//   uint8     FlagNatureWind;
    uint8     FlagAutoPower;
    uint8     FlagUserCodeSave;
    //uint8     FlagUserCodeSaveOFF;
    uint8   FlagUserCodeRead;
//    uint8   FlagLED1Protect;
//    uint8     FlagLED2Protect;
//    uint16  RunTimeLong;
    uint8  TargetSpeed;
    uint8  SpeedLevel[8];
    
    
} IRControl_TypeDef;

typedef struct
{
    uint8   FlagAutoPower;
    uint16  Timer10sec;
    uint16  ShutDowntime;
    uint16  CurrentTime;
} IRControl_AutoPowerDef;

extern IRControl_AutoPowerDef AutoPowerState;
extern IRScan_TypeDef xdata IRScan;
extern IRControl_TypeDef xdata IRControl;

/* Exported functions ---------------------------------------------------------------------------*/
extern void IRInit(void);
//extern void IRValue(void);
extern void SetSpeed(uint8 SpeedLevel);
extern void SetAutoPower(uint16 Time);
//extern void IRScanControl(void);
//extern void AutoPowerControl(void);
//extern uint8 GetUserCode(void);
//extern void IRONOFF_Control(void);
//extern void NatureWind(void);
//extern void LEDDisplay(void);
#endif